// @Author EthanScriptOn
// @Desc
package common

import (
	"gitee.com/fatzeng/srf_switch_client_demo/common/operator_define/mysql_define"
	"gitee.com/fatzeng/srf_switch_stream_bridge/bridge"
	"gitee.com/fatzeng/srf_switch_stream_bridge/framework/actuator"
	"gitee.com/fatzeng/srf_switch_stream_bridge/framework/holder"
)

type Extreme string

const CONSUMER Extreme = "CONSUMER"
const PRODUCER Extreme = "PRODUCER"

var BridgeCenterConfig = make(map[string]*bridge.BridgeConfig)
var ExecutorMappingRelationship = make(map[Extreme]map[bridge.Group]*ExecutionElement)

type ExecutionElement struct {
	Ctx      *actuator.SrfSwitchActuatorContext
	Executor actuator.Executor
}

func Initialization() {
	cacheBridgeConfig()
	cacheExecutionElement()
}

func cacheExecutionElement() {
	groupProducer := bridge.Group{Env: "test", NameSpace: "test-namespace", Group: "test-group"}
	producerMapping := ExecutorMappingRelationship[PRODUCER]
	producerMapping[groupProducer] = &ExecutionElement{
		Ctx: actuator.GenerateSrfSwitchActuatorContext(&bridge.GroupConfig{
			Group:         &groupProducer,
			BridgeConfigs: []*bridge.BridgeConfig{BridgeCenterConfig[mysql_define.MYSQL_FOREGROUND_BRIDGE_CONFIG]},
		}, holder.MILLISECOND, false),
		Executor: actuator.GenerateBridgeExecutor(),
	}
	groupConsumer := bridge.Group{Env: "test", NameSpace: "test-namespace", Group: "test-group"}
	consumerMapping := ExecutorMappingRelationship[CONSUMER]
	consumerMapping[groupConsumer] = &ExecutionElement{
		Ctx: actuator.GenerateSrfSwitchActuatorContext(&bridge.GroupConfig{
			Group:         &groupConsumer,
			BridgeConfigs: []*bridge.BridgeConfig{BridgeCenterConfig[mysql_define.MYSQL_BACKGROUND_BRIDGE_CONFIG]},
		}, holder.MILLISECOND, false),
		Executor: actuator.GenerateBridgeExecutor(),
	}
	//......
}

func cacheBridgeConfig() {
	BridgeCenterConfig[mysql_define.MYSQL_FOREGROUND_BRIDGE_CONFIG] = mysql_define.MysqlForegroundBridgeConfig()
	BridgeCenterConfig[mysql_define.MYSQL_BACKGROUND_BRIDGE_CONFIG] = mysql_define.MysqlBackgroundBridgeConfig()
	//......
}
